// Arc defination 


#include "Arc.h"



Arc::Arc(){

     //points = new Matrix(1,1);
     initialPoint = 0;
}


Arc::Arc(const MyDisplay &another):Polyline(another){

   //Arc();   

  //pointss = new Matrix(1,1);
  initialPoint = 0;
  
}

Arc::Arc(const Matrix &R):Polyline(R){


   //pointss = new Matrix(R);
     initialPoint = 0;
}


Arc::Arc(const char *fileName,const MyDisplay &another):Polyline(fileName,another){

     //pointss = new Matrix(fileName);    
 initialPoint = 0;
      
}


Arc::~Arc(){

}


bool Arc::draw(){

  for(int i = 1;i< (*points).numRows();i = i+3){
  
  draw((*points)[i][0],(*points)[i][1],(*points)[i+1][0],(*points)[i+1][1],(*points)[i+2][0],(*points)[i+2][1]);
  initialPoint = initialPoint + 3;
  
  }
  
  initialPoint = 0;
return true;
}




bool Arc::draw(const Matrix &T){

 // not done
 //incomplete

     (*points) = T;
     
     draw(); 
   
   return false;
}


bool Arc::draw(const char *fileName){

     Matrix T(fileName);
     
     (*points) = T;
     
     draw();
     
     return true;
}



bool Arc::draw(double xb,double yb,double xc,double yc,double xd,double yd, int n){

     double xab,xbc,xcd;
     double yab,ybc,ycd;         
     double xabc,yabc,xbcd,ybcd,xabcd,yabcd;
     
     
     
        if(n ==  0){
	
           plot(xb,yb);
	   plot(xc,yc);
	   plot(xd,yd);  	
	
  	
//	   cout<<" excute  "<<n<< endl;
	   
	   
	}else{
	
	    
	 xab = ((*points)[initialPoint][0] + xb) /2;
	 yab = ((*points)[initialPoint][1] + yb) /2;
	 
	 xbc = (xb + xc) / 2;
	 ybc = (yb + yc) / 2;
	 
         xcd = (xc + xd) / 2;
	 ycd = (yd + yc) / 2;
	 
	 xabc = (xab + xbc) / 2;
	 yabc = (yab + ybc) / 2; 
	
	 xbcd = (xcd + xbc) / 2;
	 ybcd = (ycd + ybc) / 2; 
	 
	 xabcd = (xabc + xbcd) / 2;
	 yabcd = (yabc + ybcd) / 2; 
	
	 n--;
	
	 draw(xab,yab,xabc,yabc,xabcd,yabcd,n);
	 draw(xbcd,ybcd,xcd,ycd,xd,yd,n);
	
       }

          return true;   
}


bool Arc::plot(const double x,const double y){

      drawLine((*points)[initialPoint][0],(*points)[initialPoint][1], x,y);
      
      (*points)[initialPoint][0] = x;
      (*points)[initialPoint][1] = y;
      
      return true;
	



}
